package com.qf.fmmall.service.impl;

import com.qf.fmmall.dao.UserAddrMapper;
import com.qf.fmmall.entity.UserAddr;
import com.qf.fmmall.service.UserAddrService;
import com.qf.fmmall.vo.ResStatus;
import com.qf.fmmall.vo.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

@Service
public class UserAddrServiceImpl implements UserAddrService {

    @Autowired
    private UserAddrMapper userAddrMapper;

    @Transactional(propagation = Propagation.SUPPORTS)
    @Override
    public ResultVo listaddrByUserId(Integer userId) {
        ResultVo vo = new ResultVo();
        Example example = new Example(UserAddr.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("userId",userId);
        List<UserAddr> userAddrs = userAddrMapper.selectByExample(example);
        if (userAddrs.size()==0){
            vo.setCode(ResStatus.NO);
            vo.setMsg("没有查询到用户的收货地址");
        }else {
            vo.setCode(ResStatus.OK);
            vo.setMsg("success");
            vo.setData(userAddrs);
        }
        return vo;
    }
}
